﻿@using ZBJF.Warranty.Common.Enums.InsuranceWarranty
@using ZBJF.Warranty.WebProvider
@using ZBJF.Warranty.Common.Enums
@{
    ViewBag.Title = "已处理工单";
}
@section Header{
    @Scripts.Render("~/bundles/datatable")
    @Styles.Render("~/Content/datatable")
}
@model ZBJF.Warranty.Model.InsuranceWarrantyRecord
<ul class="nav nav-tabs">
    <li class="active">
        <a href="/ProcessedWorkOrderWorkOrder/Index?InsuranceWarrantyRecordTaskType=@((byte)InsuranceWarrantyRecordTaskType.ProcessedWorkOrder)">
            @(ZBJF.Warranty.Common.Common.EnumHelper.Instance.GetDescription(typeof(InsuranceWarrantyRecordTaskType), (byte)InsuranceWarrantyRecordTaskType.ProcessedWorkOrder))
        </a>
    </li>
</ul>
@using (Html.BeginForm("ExportInsuranceWarrantyRecordList", "InsuranceWarrantyRecord", FormMethod.Post, new { id = "excelForm" }))
{
    @Html.Hidden("InsuranceWarrantyRecordTaskType", (byte)InsuranceWarrantyRecordTaskType.ProcessedWorkOrder)
    <table>
        <tr>
            <td>工单号：</td>
            <td>
                @Html.TextBoxFor(m => m.WarrantyRecordNo, new { @class = "input-small" })
            </td>
            <td>报案人：</td>
            <td>@Html.TextBoxFor(m => m.Reporter, new { maxlength = 20, @class = "input-small" })</td>
            <td>报案人电话：</td>
            <td>@Html.TextBoxFor(m => m.ReporterPhone, new { maxlength = 20, @class = "input-small" })</td>
            <td>工单状态：</td>
            <td>@Html.DropDownListFor(c => c.Status, ConvertToSelector.Instance.InsuranceWarrantyRecordConvertToSelectList((byte)InsuranceWarrantyRecordTaskType.Processed), new { @class = "w-p90" })</td>
        </tr>
        <tr>
            <td>销售商户：</td>
            <td>
                @Html.TextBox("SaleVendorName", "", new { @class = "input-small" })
            </td>
            <td>承保公司：</td>
            <td>@Html.TextBox("InsuranceCompany", "", new { maxlength = 20, @class = "input-small", onmousemove = "this.title=this.value" })</td>
            <td>承保公司分公司：</td>
            <td>@Html.TextBox("InsuranceCompanyBranch", "", new { maxlength = 20, @class = "input-small", onmousemove = "this.title=this.value" })</td>
            <td colspan="2">
                <input id="btnSubmit" class="btn Search-R margin-l-10" type="button" value="重置" onclick="reset();search();" />
                <input id="btnSubmit" class="btn btn-primary Search-R margin-l-10" type="button" value="查询" onclick="search();" />
                <input id="btnStayExport" class="btn btn-success Search-R margin-l-10" type="submit" value="导出清单" />
            </td>
        </tr>
    </table>
}
<div class="table-responsive dataTables_wrapper">
    <table id="insuranceWarrantyRecordList" class="table table-striped table-bordered table-hover">
        <thead>
            <tr>
                <th width="20">序号</th>
                <th width="100">工单号</th>
                <th width="100">报案人</th>
                <th width="100">报案人电话</th>
                <th width="100">保险产品名称</th>
                <th width="100">第三方承保公司</th>
                <th width="100">承保公司分公司</th>
                <th width="100">销售商户</th>
                <th width="100">创建时间</th>
                <th width="80">跟进人</th>
                <th width="80">总耗时</th>
                <th width="80">工单状态</th>
                <th width="80">最后编辑时间</th>
            </tr>
        </thead>
    </table>
</div>
@section scripts{
    <script src="~/Content/js/moment.js"></script>
    <script type="text/javascript">
        window.onload = function () {
            search();
        }
        function reset() {
            document.getElementById("excelForm").reset();
        }
        var isSearch = false;
        var zipFileName = '';
        $(function () {
            var objTable = $("#insuranceWarrantyRecordList")
                .dataTable({
                    fnDrawCallback: function () {
                        ControlPermissionOperate();
                    },
                    "aaSorting": [[9, "desc"]],
                    "sAjaxSource": "/ProcessedWorkOrder/Index?InsuranceWarrantyRecordTaskType=@((byte)InsuranceWarrantyRecordTaskType.ProcessedWorkOrder)",
                    aoColumns: [
                        {
                            "mData": null,
                            "bSortable": false,
                            "fnRender": function (nRow) {
                                return nRow.iDataRow + 1;
                            }
                        },
                        {
                            "mData": null, "bSortable": false, fnRender: function (nRow) {
                                return "<a  target='_blank' class='Edit-R' href='/ProcessedWorkOrder/detail/" + nRow.aData.ID + "' title=''>" + nRow.aData.WarrantyRecordNo + "</i></a>";
                            }
                        },
                        { "mData": "Reporter", "bSortable": false },
                        { "mData": "ReporterPhone", "bSortable": false },
                        { "mData": "ProductName", "bSortable": false },
                        { "mData": "InsuranceCompany", "bSortable": false },
                        { "mData": "InsuranceCompanyBranch", "bSortable": false },
                        { "mData": "SaleVendorName", "bSortable": false },
                        { "mData": "CreateTime", "bSortable": false },
                        { "mData": "ServiceUserName", "bSortable": false },
                        { "mData": "CostTotalSecond", "bSortable": false },
                        { "mData": "StatusDesc", "bSortable": false },
                        { "mData": "LastModifyTime", "bSortable": false }
                    ]
                });
        });

        function search() {
            queryParamList.WarrantyRecordNo = $("#WarrantyRecordNo").val();
            queryParamList.Reporter = $("#Reporter").val();
            queryParamList.ReporterPhone = $("#ReporterPhone").val();
            queryParamList.Status = $("#Status").val();
            queryParamList.SaleVendorName = $("#SaleVendorName").val();
            queryParamList.InsuranceCompany = $("#InsuranceCompany").val();
            queryParamList.InsuranceCompanyBranch = $("#InsuranceCompanyBranch").val();
            queryParamList.CloseOrderTimeEnd = $("#CloseOrderTimeEnd").val();
            $("#insuranceWarrantyRecordList").dataTable().fnDraw();
        }

        function getFile() {
            layer.confirm('确定要获取各项任务的附件资料吗？', {
                btn: ['确认', '取消']
            }, function (index) {
                layer.close(index);
                $.ajax({
                    url: '@Url.Action("DownloadFiles","InsuranceWarrantyRecord")',
                    dataType: "json",
                    type: "POST",
                    data: { content: "/UploadFile/File/zipOrder/" + zipFileName + ".zip" },
                    async: false,
                    success: function (data) {
                        if (data.sucess) {
                            window.location.href = "/UploadFile/File/zipOrder/" + zipFileName + ".zip";
                        }
                        else {
                            layer.alert(data.message);
                        }
                    }
                });
            }, function (index) {
                layer.close(index);
            });

        }

        $(function () {
            //导出excel
            $("#exportExcel").on("click", function () {
                layer.confirm('确定要导出已处理任务清单吗？', {
                    btn: ['确认', '取消']
                }, function (index, layero) {
                    zipFileName = Date.parse(new Date());
                    layer.confirm('是否需要同步导出各项任务的附件资料？', {
                        btn: ['是', '否']
                    }, function (index) {
                        layer.close(index);
                        exportFile(queryParamList, zipFileName, true);
                    }, function (index) {
                        layer.close(index);
                        exportFile(queryParamList, zipFileName, false);
                    });


                }, function (index) {
                });
            });
        });

        function exportFile(queryParamList, zipFileName, isNeedLoadFile) {
            $("#GetFiles").attr("href", "javascript:;").attr("onclick", "getFile()");
            search();
            queryParamList.InsuranceWarrantyRecordTaskType = "@((byte)InsuranceWarrantyRecordTaskType.ToBeProcess)";
            window.location.href = '@Url.Action("ExportInsuranceWarrantyRecord","InsuranceWarrantyRecord")?content=' + JSON.stringify(queryParamList) + "&zipFileName=" + zipFileName + "&isNeedLoadFile=" + isNeedLoadFile;
            if (isNeedLoadFile)
                $("#GetFiles").show();
        }
    </script>
}
